import {defineStore} from 'pinia'
interface UserType{
    name:string
    age:number
    job:string
}
const useUserStore=defineStore("user",{
    state():UserType{
        return{
            name:'张三丰',
            age:120,
            job:'掌门'
        }
    },
    getters:{
        getUserInfo(state:UserType){
            return `姓名:${state.name}-年龄:${state.age}-职位:${state.job}`
        }
    },
    actions:{
      modifyUserInfo(name:string,age:number,job:string){
        setTimeout(() => {
            this.name=name
            this.age=age
            this.job=job
        }, 1000);
      }  
    },
    persist:{
        enabled:true,
        strategies:[
            {
                key:'user-giles',
                storage:sessionStorage,
                paths:['name','age']
            }
        ]
    }
})
export default useUserStore